package com.hb.trade.server.center.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.center.sys.dto.CascadeQueryDTO;
import com.hb.core.pojo.center.sys.entity.DicCode;
import com.hb.core.pojo.center.sys.mapper.DicCodeMapper;
import com.hb.trade.server.center.sys.service.DicCodeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 数据字典信息 服务实现类
 *
 * @author zjk
 * @since 2021-05-21
 */
@Service
public class DicCodeServiceImpl extends ServiceImpl<DicCodeMapper, DicCode> implements DicCodeService {

    @Deprecated
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteByIds(List<Long> ids) {
        int row = this.baseMapper.deleteBatchIds(ids);
        LambdaQueryWrapper<DicCode> wrapper = new LambdaQueryWrapper<DicCode>().in(DicCode::getParentId, ids);
        this.baseMapper.delete(wrapper);
        return row > 0;
    }

    @Deprecated
    @Override
    public JSONObject getTopData(CascadeQueryDTO topQuery) {
        String paramsValid = topQuery.paramsValid();
        if (StrUtil.isEmpty(paramsValid)) {
            return baseMapper.getTopData(topQuery);
        }
        log.warn(paramsValid);
        return null;
    }

    @Override
    public List<Long> getChildList(CascadeQueryDTO topQuery) {
        String paramsValid = topQuery.paramsValid();
        if (StrUtil.isEmpty(paramsValid)) {
            return baseMapper.getChildList(topQuery);
        }
        log.warn(paramsValid);
        return null;
    }


    /**
     * 根据类型代码和值查询字典名称
     * @author tian
     * @date 2022-3-1 15:55
     * @param typeCode 类型代码
     * @param dicLabel 值
     * @return com.hb.core.pojo.center.sys.entity.DicCode
     */
    @Override
    public DicCode selectDicCodeByTypeCodeAndDicLabel(String typeCode, String dicLabel) {
        DicCode dicCode = baseMapper.selectDicCodeByTypeCodeAndDicLabel(typeCode, dicLabel);
        if(null != dicCode){
            return dicCode;
        }
        return new DicCode();
    }
}
